<?php 
  
 class BannerWebModule extends WebModule 
 { 
    protected $id='banner';
    protected static $defaultModel = 'BannerDataModel';
    protected $feeds = array();

    public function getHomeScreenBanner() {
        $listArr = array();
        foreach($this->feeds as $feed => $feedData){
            $list['title'] = $feedData['IMAGE_URL'];
            $list['url'] = $feedData['BASE_URL'];
            $listArr[] = $list;
        }
        return $listArr;
    }
        
    protected function initialize() {
        $this->feeds = $this->loadFeedData();
        $this->maxPerPage = $this->getOptionalModuleVar('MAX_RESULTS', 20);
        if (count($this->feeds)==0) {
            return;
        }
    } 

    protected function getDefaultSection() {
        return key($this->feeds);
    }

    protected function getFeed($feed = null) {
        $feed = isset($this->feeds[$feed]) ? $feed : $this->getDefaultSection();
        $feedData = $this->feeds[$feed];
        $feedData['RETRIEVER_CLASS'] = 'BannerDataRetriever';
       // $feedData['PARSER_CLASS'] = 'JSONDataParser';

        $modelClass = isset($feedData['MODEL_CLASS']) ? $feedData['MODEL_CLASS'] : self::$defaultModel;
        $controller = DataModel::factory($modelClass, $feedData);
        return $controller;
    }

    protected function initializeForPage() { 

        if (count($this->feeds) == 0) {
            throw new KurogoConfigurationException($this->getLocalizedString('BANNER_FEED_CONFIGURE_ERROR_MESSAGE'));
        }

        switch ($this->page) 
        { 
            case 'index': 
                foreach($this->feeds as $feed => $feedData){
                    $list['title'] = $feedData['IMAGE_URL'];
                    $list['url'] = $feedData['BASE_URL'];
                    $listArr[] = $list;
                }
                $this->assign('listArr', $listArr);
                break;
         } 
     } 
 }
